package be.g00glen00b.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import twitter4j.TwitterException;
import be.g00glen00b.service.TwitterService;

@Controller
public class MainController {

	@Autowired
	private TwitterService service;

	@RequestMapping(value = "/index.html")
	public String getIndex(ModelMap model) {
		try {
			model.addAttribute("tweets", service.getTweets("g00glen00b"));
			return "index";
		} catch (TwitterException ex) {
			model.addAttribute("error", ex.getMessage());
			return "error";
		}
	}
}
